package springdao.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.jdo.annotations.Column;
import javax.jdo.annotations.Element;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Order;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 *
 * @author Kent Yeh
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, table = "storage", detachable = "true")
public class Storage implements Serializable {

    private static final long serialVersionUID = 4119657693199960543L;
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.UNSPECIFIED)
    private Integer sid;
    @Persistent
    @Column(jdbcType = "VARCHAR", length = 10)
    private String location;
    @Persistent(mappedBy = "owner", defaultFetchGroup = "true")
    @Element
//    @Order(column = "sid asc")
    private Set<UserStore> userstores = new HashSet<UserStore>();

    public Storage() {
    }

    public Storage(Integer sid) {
        this.sid = sid;
    }

    public Integer getSid() {
        return sid;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public Set<UserStore> getUserstore() {
        return userstores;
    }

    public void setUserstore(Set<UserStore> userstores) {
        this.userstores = userstores;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Storage other = (Storage) obj;
        if (this.sid != other.sid && (this.sid == null || !this.sid.equals(other.sid))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.sid != null ? this.sid.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return String.format("%s[%s]", location, sid);
    }
}
